Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 11526 - H(n) / 11526.cpp
blobbe3c2c364451b34fd2697f429635e78d43414729
1 #include <iostream>
2 #include <cstdio>
3 using namespace std;
5 long long n;
6 int main(){
7 int t; cin >> t;
8 while (t-- && cin >> n){
9 if (n <= 0){ cout << "0" << endl; continue; }
11 long long res = 0;
12 long long i = 1;
13 while (i <= n){
14 long long start = n / i;
15 long long low = i, high = n;
16 while (low < high){
17 //long long mid = (low + high + 1) / 2;//low + (high - low + 1) / 2;
18 long long mid = low + (high - low + 1) / 2;
19 //printf("low=%lld, high=%lld, mid=%lld, i=%lld\n", low, high, mid, i);
20 if (n / mid != start) high = mid - 1;
21 else low = mid;
23 res += (low - i + 1) * start;
24 i = low + 1;
26 cout << res << endl;
28 return 0;